var path = require("path");
var webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var autoprefixer = require('autoprefixer')

// definePlugin 接收字符串插入到代码当中, 所以你需要的话可以写上 JS 的字符串.mock dev prod test
var definePlugin = new webpack.DefinePlugin({
    __ENV__: JSON.stringify(process.env.ENV || 'prod')
});
    
module.exports = {
    entry: {
        "home/register/bundle":["./js/home/register/app.js"],
        "home/login/bundle":["./js/home/login/app.js"],
        "home/Settings/bundle":["./js/home/Settings/app.js"],
        "home/personalData/bundle":["./js/home/personalData/app.js"],
        "home/userInfo/bundle":["./js/home/userInfo/app.js"],
        "home/shopInfo/bundle":["./js/home/shopInfo/app.js"],

        "home/bulletin/bundle":["./js/home/bulletin/app.js"],
        "home/QR_code/bundle":["./js/home/QR_code/app.js"],
        "home/shopApplication/bundle":["./js/home/shopApplication/app.js"],
        "home/shopApplication_License/bundle":["./js/home/shopApplication_License/app.js"],
        "home/BankAccount/bundle":["./js/home/BankAccount/app.js"],
        "home/shopApplyfeedback/bundle":["./js/home/shopApplyfeedback/app.js"],
        "home/addBank/bundle":["./js/home/addBank/app.js"],
        "home/certification/bundle":["./js/home/certification/app.js"],
        "home/certification_register/bundle":["./js/home/certification_register/app.js"],

        "home/addBank_realName/bundle":["./js/home/addBank_realName/app.js"],
        "home/BankCardList/bundle":["./js/home/BankCardList/app.js"],
        "home/transBank_firm/bundle":["./js/home/transBank_firm/app.js"],
        "home/transBank/bundle":["./js/home/transBank/app.js"],
        "home/addBank_firm/bundle":["./js/home/addBank_firm/app.js"],
        "home/registeredConsumption/bundle":["./js/home/registeredConsumption/app.js"],
        "home/forgetPassword/bundle":["./js/home/forgetPassword/app.js"],
        "home/changePassword/bundle":["./js/home/changePassword/app.js"],
        "home/TwoPassword/bundle":["./js/home/TwoPassword/app.js"],
        "home/alterPhone/bundle":["./js/home/alterPhone/app.js"],
        "home/bank/bundle":["./js/home/bank/app.js"],
        "home/bank_firm/bundle":["./js/home/bank_firm/app.js"],
        "home/BusinessInfo/bundle":["./js/home/BusinessInfo/app.js"],
        "home/Transfer/bundle":["./js/home/Transfer/app.js"],
        "home/WeChatPay/bundle":["./js/home/WeChatPay/app.js"],
        "home/consumptionCertificate/bundle":["./js/home/consumptionCertificate/app.js"],
        "home/consumerAudit/bundle":["./js/home/consumerAudit/app.js"],
        "home/expensesRecord_shop/bundle":["./js/home/expensesRecord_shop/app.js"],
        "home/remittanceVoucher/bundle":["./js/home/remittanceVoucher/app.js"],

        "home/pointsDetail/bundle":["./js/home/pointsDetail/app.js"],
        "home/pointsJlDetail/bundle":["./js/home/pointsJlDetail/app.js"],
        "home/pointsXDetail/bundle":["./js/home/pointsXDetail/app.js"],
        "home/fundsDetail/bundle":["./js/home/fundsDetail/app.js"],
        "home/enjoyPointsOperate/bundle":["./js/home/enjoyPointsOperate/app.js"],
        "home/recommend/bundle":["./js/home/recommend/app.js"],
        "home/bulletinDetail/bundle":["./js/home/bulletinDetail/app.js"],

        "home/consumerInquiries/bundle":["./js/home/consumerInquiries/app.js"],
        "home/consumerInquiriesDetail/bundle":["./js/home/consumerInquiriesDetail/app.js"],
        "home/expensesRecord_revocation/bundle":["./js/home/expensesRecord_revocation/app.js"],
        "home/expensesRecord_revoked/bundle":["./js/home/expensesRecord_revoked/app.js"],
        "home/consumeRecord/bundle":["./js/home/consumeRecord/app.js"],
        "home/consumerInquiriesDetail_user/bundle":["./js/home/consumerInquiriesDetail_user/app.js"],
        "home/Message/bundle":["./js/home/Message/app.js"],

        "home/alliance/bundle":["./js/home/alliance/app.js"],
        "home/allianceDetail/bundle":["./js/home/allianceDetail/app.js"],
        "home/lore/bundle":["./js/home/lore/app.js"],

        "home/avatarList/bundle":["./js/home/avatarList/app.js"],
        "home/guide/bundle":["./js/home/guide/app.js"],
        "home/NoInvitation/bundle":["./js/home/NoInvitation/app.js"]
    },
    output: {
        path: __dirname + '/js/dist/',
        filename: "[name].js",
        publicPath: "/js/dist/",
        chunkFilename: "[name]_[id].js"
    },
    module: {
        loaders: [
        {
            test: /\.less$/,
            loader: ExtractTextPlugin.extract('style-loader', 'css-loader!postcss-loader!less-loader')
        }, {
            test: /\.css$/,
            loader: ExtractTextPlugin.extract('style-loader', 'css-loader', 'autoprefixer-loader')
        }, {
            test: /\.png$/,
            loader: 'url?limit=8192&mimetype=image/png'
        }, {
            test: /\.jpe?g$/,
            loader: 'url?limit=8192&mimetype=image/jpg'
        }, {
            test: /\.gif$/,
            loader: 'url?limit=8192&mimetype=image/gif'
        }, {
            test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
            loader: 'url?limit=8192&mimetype=image/svg+xml'
        }, {
            test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
            loader: 'url?limit=8192&mimetype=application/font-woff2'
        }, {
            test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
            loader: 'url?limit=8192&mimetype=application/font-woff'
        }, {
            test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
            loader: 'url?limit=8192&mimetype=application/octet-stream'
        }, {
            test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
            loader: 'file'
        }, {
            test: /\.hbs$/,
            loader: "handlebars-template-loader",
            query: {
                prependFilenameComment: __dirname,
            }
        }, {
            test: /\.json$/,
            loader: "json-loader"
        }, {
            test: /\.(html|temp)$/,
            loader: "html"
        },
        ]
    },
    node: {
        fs: "empty" // avoids error messages
    },
    resolve: {
        root: [
            path.resolve('./js'),
            path.resolve('./js/lib'),
            path.resolve('./js/common'),
            path.resolve('./style')
        ],
        alias: {
            'vue$': 'vue/dist/vue.js'
        }
    },
    vue: {
        loaders: {
            css: 'style!css!autoprefixer',
            html:'html-loader'
        }
    },
    plugins: [
        definePlugin,
        new webpack.ResolverPlugin(
            new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin(".bower.json", ["main"])
        ),
        new ExtractTextPlugin("[name].css"),
        /*new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false
            }
        })*/
    ],
    postcss: [autoprefixer({
        browsers: ['last 2 versions']
    })],
    devtool: "source-map",
    devServer: {
        port: 8080,
        host: "0.0.0.0",
        proxy: {
            '/mock/*': {
                target: 'http://localhost:3000/mock',
                secure: false
            },
        }
    }
};